import { createSlice } from '@reduxjs/toolkit'

type init = {
  isDark: boolean
}

const initialState: init = {
  isDark: localStorage.getItem('ISDARK')
    ? (JSON.parse(localStorage.getItem('ISDARK') as string) as boolean)
    : false
}

const systemSlicer = createSlice({
  name: 'system',
  initialState: initialState,
  reducers: {
    changeSystemColor: (state, action) => {
      state.isDark = action.payload
    }
  }
})

// 为每个 case reducer 函数生成 Action creators
export const { changeSystemColor } = systemSlicer.actions

export default systemSlicer.reducer
